home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / librw / RWTIsvSlist.z / RWTIsvSlist
Encoding:
Text File  |  1998-10-30  |  15.7 KB  |  463 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWTIsvSlist<T> - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/tislist.h>
  13.  
  14.  
  15.  
  16.               RWTIsvSlist<T> list;
  17.  
  18.  
  19.  
  20.  
  21. DDDDeeeessssccccrrrriiiippppttttoooonnnn
  22.      Class RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt<<<<TTTT>>>> is a class that implements intrusive singly-linked
  23.      lists. An intrusive list is one where the member of the list must inherit
  24.      from a common base class, in this case RRRRWWWWIIIIssssvvvvSSSSlllliiiinnnnkkkk.  The advantage of such
  25.      a list is that memory and space requirements are kept to a minimum.  The
  26.      disadvantage is that the inheritance hierarchy is inflexible, making it
  27.      slightly more difficult to use with an existing class.  Class
  28.      RRRRWWWWTTTTVVVVaaaallllSSSSlllliiiisssstttt<<<<TTTT>>>> is offered as an alternative, non-intrusive, linked list.
  29.      See Stroustrup (1991; Section 8.3.1) for more information about intrusive
  30.      lists.  NNNNooootttteeee tttthhhhaaaatttt wwwwhhhheeeennnn yyyyoooouuuu iiiinnnnsssseeeerrrrtttt aaaannnn iiiitttteeeemmmm iiiinnnnttttoooo aaaannnn iiiinnnnttttrrrruuuussssiiiivvvveeee lllliiiisssstttt,,,, tttthhhheeee
  31.      aaaaccccttttuuuuaaaallll iiiitttteeeemmmm ((((nnnnooootttt aaaa ccccooooppppyyyy)))) iiiissss iiiinnnnsssseeeerrrrtttteeeedddd....  BBBBeeeeccccaaaauuuusssseeee eeeeaaaacccchhhh iiiitttteeeemmmm ccccaaaarrrrrrrriiiieeeessss oooonnnnllllyyyy oooonnnneeee
  32.      lllliiiinnnnkkkk ffffiiiieeeelllldddd,,,, tttthhhheeee ssssaaaammmmeeee iiiitttteeeemmmm ccccaaaannnnnnnnooootttt bbbbeeee iiiinnnnsssseeeerrrrtttteeeedddd iiiinnnnttttoooo mmmmoooorrrreeee tttthhhhaaaannnn oooonnnneeee lllliiiisssstttt,,,, nnnnoooorrrr
  33.      ccccaaaannnn iiiitttt bbbbeeee iiiinnnnsssseeeerrrrtttteeeedddd iiiinnnnttttoooo tttthhhheeee ssssaaaammmmeeee lllliiiisssstttt mmmmoooorrrreeee tttthhhhaaaannnn oooonnnncccceeee....
  34.  
  35.  
  36. EEEExxxxaaaammmmpppplllleeee
  37.               #include <rw/tislist.h>
  38.           #include <rw/rstream.h>
  39.           #include <string.h>
  40.  
  41.  
  42.               struct Symbol : public RWIsvSlink
  43.  
  44.  
  45.  
  46.               { char name[10];
  47.             Symbol( const char* cs)
  48.              { strncpy(name, cs, sizeof(name)); name[9] = ' '; }
  49.           };
  50.  
  51.  
  52.               void printem(Symbol* s, void*) { cout << s->name << endl; }
  53.           main(){
  54.  
  55.  
  56.  
  57.                 RWTIsvSlist<Symbol> list;
  58.             list.insert( new Symbol("one") );
  59.             list.insert( new Symbol("two") );
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.             list.prepend( new Symbol("zero") );
  75.  
  76.  
  77.                 list.apply(printem, 0);
  78.  
  79.  
  80.  
  81.                 list.clearAndDestroy();  // Deletes the items inserted into
  82.                                      // the list
  83.             return 0;
  84.           }
  85.  
  86.      PPPPrrrrooooggggrrrraaaammmm OOOOuuuuttttppppuuuutttt::::
  87.  
  88.               zero
  89.           one
  90.  
  91. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
  92.      two
  93.  
  94.  
  95.  
  96.               RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt();
  97.  
  98.  
  99.      Constructs an empty list.
  100.  
  101.               RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt(T* a);
  102.  
  103.  
  104.      Constructs a list with the single item pointed to by aaaa in it.
  105.  
  106. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  107.               void
  108.           aaaappppppppeeeennnndddd(T* a);
  109.  
  110.  
  111.      Appends the item pointed to by aaaa to the end of the list.
  112.  
  113.               void
  114.           aaaappppppppllllyyyy(void (*applyFun)(T*, void*), void* d);
  115.  
  116.  
  117.      Calls the function pointed to by aaaappppppppllllyyyyFFFFuuuunnnn to every item in the
  118.      collection.  This must have the prototype:
  119.  
  120.               void yyyyoooouuuurrrrFFFFuuuunnnn(T* item, void* d);
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.  
  141.  
  142.      The item will be passed in as argument iiiitttteeeemmmm.  Client data may be passed
  143.      through as parameter dddd.
  144.  
  145.               T*
  146.           aaaatttt(size_t i) const;
  147.  
  148.  
  149.      Returns the item at index iiii.  The index iiii must be between zero and the
  150.      number of items in the collection less one, or an exception of type
  151.      TTTTOOOOOOOOLLLL____IIIINNNNDDDDEEEEXXXX will be thrown.
  152.  
  153.               void
  154.           cccclllleeeeaaaarrrr();
  155.  
  156.  
  157.      Removes all items from the list.
  158.  
  159.               void
  160.           cccclllleeeeaaaarrrrAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy();
  161.  
  162.  
  163.      Removes aaaannnndddd ccccaaaallllllllssss ddddeeeelllleeeetttteeee for each item in the list.  Note that this
  164.      assumes that each item was allocated off the heap.
  165.  
  166.               RWBoolean
  167.           ccccoooonnnnttttaaaaiiiinnnnssss(RWBoolean (*testFun)(const T*, void*), void* d)
  168.                    const;
  169.  
  170.  
  171.      Returns TTTTRRRRUUUUEEEE if the list contains an item for which the user-defined
  172.      "tester" function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE .  The tester
  173.      function must have the prototype:
  174.  
  175.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(const T* item, void* d);
  176.  
  177.  
  178.  
  179.  
  180.  
  181.      For each item in the list this function will be called with the item as
  182.      the first argument.  Client data may be passed through as parameter dddd.
  183.  
  184.               RWBoolean
  185.           ccccoooonnnnttttaaaaiiiinnnnssssRRRReeeeffffeeeerrrreeeennnncccceeee(const T* a) const;
  186.  
  187.  
  188.      Returns TTTTRRRRUUUUEEEE if the list contains an item with the address aaaa.
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.               size_t
  207.           eeeennnnttttrrrriiiieeeessss() const;
  208.  
  209.  
  210.      Returns the number of items currently in the list.
  211.  
  212.               T*
  213.           ffffiiiinnnndddd(RWBoolean (*testFun)(const T*, void*),void* d) const;
  214.  
  215.  
  216.      Returns the first item in the list for which the user-defined "tester"
  217.      function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE.  If there is no such item,
  218.      then returns nnnniiiillll.  The tester function must have the prototype:
  219.  
  220.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(const T* item, void* d);
  221.  
  222.  
  223.  
  224.  
  225.  
  226.      For each item in the list this function will be called with the item as
  227.      the first argument.  Client data may be passed through as parameter dddd.
  228.  
  229.               T*
  230.           ffffiiiirrrrsssstttt() const;
  231.  
  232.  
  233.      Returns (but does not remove) the first item in the list, or nnnniiiillll if the
  234.      list is empty.
  235.  
  236.               T*
  237.           ggggeeeetttt();
  238.  
  239.  
  240.      Returns aaaannnndddd rrrreeeemmmmoooovvvveeeessss the first item in the list, or nnnniiiillll if the list is
  241.      empty.
  242.  
  243.               size_t
  244.           iiiinnnnddddeeeexxxx(RWBoolean (*testFun)(const T*, void*),void* d) const;
  245.  
  246.  
  247.      Returns the index of the first item in the list for which the user-
  248.      defined "tester" function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE.  If there
  249.      is no such item, then returns RRRRWWWW____NNNNPPPPOOOOSSSS.  The tester function must have the
  250.      prototype:
  251.  
  252.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(const T* item, void* d);
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt((((3333CCCC++++++++))))
  269.  
  270.  
  271.  
  272.  
  273.  
  274.      For each item in the list this function will be called with the item as
  275.      the first argument.  Client data may be passed through as parameter dddd.
  276.  
  277.               void
  278.           iiiinnnnsssseeeerrrrtttt(T* a);
  279.  
  280.  
  281.      Appends the item pointed to by aaaa to the end of the list.  This item
  282.      cannot be inserted into more than one list, nor can it be inserted into
  283.      the same list more than once.
  284.  
  285.               void
  286.           iiiinnnnsssseeeerrrrttttAAAAtttt(size_t i, T* a);
  287.  
  288.  
  289.      Insert the item pointed to by aaaa at the index position iiii.  This position
  290.      must be between zero and the number of items in the list, or an exception
  291.      of type TTTTOOOOOOOOLLLL____IIIINNNNDDDDEEEEXXXX will be thrown.  The item cannot be inserted into more
  292.      than one list, nor can it be inserted into the same list more than once.
  293.  
  294.               RWBoolean
  295.           iiiissssEEEEmmmmppppttttyyyy() const;
  296.  
  297.  
  298.      Returns TTTTRRRRUUUUEEEE if there are no items in the list, FFFFAAAALLLLSSSSEEEE otherwise.
  299.  
  300.               T*
  301.           llllaaaasssstttt() const;
  302.  
  303.  
  304.      Returns (but does not remove) the last item in the list, or nnnniiiillll if the
  305.      list is empty.
  306.  
  307.               size_t
  308.           ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(RWBoolean (*testFun)(const T*, void*),void* d)
  309.                         const;
  310.  
  311.  
  312.      Traverses the list and returns the number of times for which the user-
  313.      defined "tester" function pointed to by tttteeeessssttttFFFFuuuunnnn returned TTTTRRRRUUUUEEEE .  The
  314.      tester function must have the prototype:
  315.  
  316.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(const T* item, void* d);
  317.  
  318.  
  319.  
  320.  
  321.  
  322.      For each item in the list this function will be called with the item as
  323.      the first argument.  Client data may be passed through as parameter dddd.
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt((((3333CCCC++++++++))))
  335.  
  336.  
  337.  
  338.               size_t
  339.           ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffffRRRReeeeffffeeeerrrreeeennnncccceeee(const T* a) const;
  340.  
  341.  
  342.      Returns the number of times which the item pointed to by aaaa occurs in the
  343.      list.  Because items cannot be inserted into a list more than once, this
  344.      function can only return zero or one.
  345.  
  346.               void
  347.           pppprrrreeeeppppeeeennnndddd(T* a);
  348.  
  349.  
  350.      Prepends the item pointed to by aaaa to the beginning of the list.
  351.  
  352.               T*
  353.           rrrreeeemmmmoooovvvveeee(RWBoolean (*testFun)(const T*, void*),void* d);
  354.  
  355.  
  356.      Removes and returns the first item for which the user-defined tester
  357.      function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE, or nnnniiiillll if there is no such
  358.      item.  The tester function must have the prototype:
  359.  
  360.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(const T* item, void* d);
  361.  
  362.  
  363.  
  364.  
  365.  
  366.      For each item in the list this function will be called with the item as
  367.      the first argument.  Client data may be passed through as parameter dddd.
  368.  
  369.               T*
  370.           rrrreeeemmmmoooovvvveeeeAAAAtttt(size_t i);
  371.  
  372.  
  373.      Removes and returns the item at index iiii.  The index iiii must be between
  374.      zero and the number of items in the collection less one or an exception
  375.      of type TTTTOOOOOOOOLLLL____IIIINNNNDDDDEEEEXXXX will be thrown.
  376.  
  377.               T*
  378.           rrrreeeemmmmoooovvvveeeeFFFFiiiirrrrsssstttt();
  379.  
  380.  
  381.      Removes and returns the first item in the list, or nnnniiiillll if there are no
  382.      items in the list.
  383.  
  384.               T*
  385.           rrrreeeemmmmoooovvvveeeeLLLLaaaasssstttt();
  386.  
  387.  
  388.      Removes and returns the last item in the list, or nnnniiiillll if there are no
  389.      items in the list.  This function is relatively slow because removing the
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTIIIIssssvvvvSSSSlllliiiisssstttt((((3333CCCC++++++++))))
  401.  
  402.  
  403.  
  404.      last link in a singly-linked list necessitates access to the next-to-
  405.      the-last link, requiring the whole list to be searched.
  406.  
  407.               T*
  408.           rrrreeeemmmmoooovvvveeeeRRRReeeeffffeeeerrrreeeennnncccceeee(T* a);
  409.  
  410.  
  411.      Removes and returns the link with address aaaa.  The link must be in the
  412.      list.  In a singly-linked list this function is not very efficient.
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.